package com.momo.web.controller.sysmain;

import com.alibaba.fastjson.JSONObject;
import com.momo.common.common.JSONResult;
import com.momo.common.req.sysmain.LoginUserReq;
import com.momo.common.res.sysmain.ResPonseUser;
import com.momo.service.sysmain.SystemMainService;
import com.momo.web.aop.MethodLog;
import com.momo.web.controller.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;

/**
 * Created by 李杰 on 2019/2/10.
 */
@RestController
@RequestMapping(value = "/platform/sysMain", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
@Slf4j
public class SystemMainController extends BaseController {
    @Autowired
    private SystemMainService systemMainService;

    /**
     * 用户登录
     *
     * @param loginUserReq
     * @return
     */
    @PostMapping("/login/v1")
//    @MethodLog(description = "保存-方法名称save", clazz = ResPonseUser.class)
    public JSONResult userLogin(@Validated(LoginUserReq.Query.class) @RequestBody LoginUserReq loginUserReq, HttpServletRequest request, ResPonseUser resPonseUser) {
        return systemMainService.userLogin(loginUserReq, request);
    }

    /**
     * 测试
     *
     * @return
     */
    @PostMapping("/test/v1")
//    @MethodLog(description = "保存-方法名称save", clazz = ResPonseUser.class)
    public JSONResult test() {
        try {
            return JSONResult.ok(this.redisUser());
        }catch (UnsupportedEncodingException e){
            return JSONResult.errorMap("测试出错");
        }

    }
}
